Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
Want to check for all DIV ID and match with anchor link in UL LI a[href], if match found then add a class to the LI items

I really am facing a complex situation here.
I have created an event page. Each page will have multiple sections like CULTURE, FOOD, SPORTS and each section will have events. I already set a system that has a nav tag, inside the nav tag we have ul li a[#anchor-links]. I have this code that will look for Div id when it is visible it will add an active class to that list item.
Now, in the sidebar, under each li item, I create 12 more li items for months. That will DISPLAY NONE initially and display inline-block when the mother LI has a class ACTIVE. What I am trying is to find all DIV ID for a month as well, and compare with these 12 li a[href], then months we have events on, I want that those link active and show a special class.
These are ID I added
Culture - #culture . Events under culture like #culture-jan,#culture-feb
Food - #food. Events under food like #food-jan,#food-fed ....
This is the JQuery I am using so far

<script>
window.addEventListener('DOMContentLoaded', () => {

  const observer = new IntersectionObserver(entries => {
    entries.forEach(entry => {
      const id = entry.target.getAttribute('id');
      if (entry.intersectionRatio > 0) {
        document.querySelector(`nav li a[href="#${id}"]`).parentElement.classList.add('active');
      } else {
        document.querySelector(`nav li a[href="#${id}"]`).parentElement.classList.remove('active');
      }
    });
  });

  // Track all sections that have an `id` applied
  document.querySelectorAll('div[id]').forEach((div) => {
    observer.observe(div);
  });
  
});
</script>


Please anyone, help. Thanks
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda